import 'package:connectivity/connectivity.dart';
import 'package:dio/dio.dart';

import '../api_code.dart';
import '../api_result.dart';

/// 错误拦截
class ErrorInterceptors extends InterceptorsWrapper {
  ErrorInterceptors();

  @override
  onRequest(RequestOptions options) async {

    /// 没有网络
    var connectivityResult = await (new Connectivity().checkConnectivity());
    if (connectivityResult == ConnectivityResult.none) {
      return ResultData(
          ApiCode.errorHandleFunction(
              ApiCode.NETWORK_ERROR, "网络错误，请检查网络", false),
          false,
          ApiCode.NETWORK_ERROR);
    }
    return options;
  }
}
